package com.itheima.restkeeper.face;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.restkeeper.ApicertFace;
import com.itheima.restkeeper.pojo.Apicert;
import com.itheima.restkeeper.req.ApicertVo;
import com.itheima.restkeeper.service.IApicertService;
import com.itheima.restkeeper.utils.BeanConv;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.annotation.Method;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @ClassName ApicertFaceImpl.java
 * @Description 品牌dubbo接口定义实现
 */
@DubboService(version = "${dubbo.application.version}",timeout = 5000,
    methods ={
        @Method(name = "findApicertVoPage",retries = 2),
        @Method(name = "createApicert",retries = 0),
        @Method(name = "updateApicert",retries = 0),
        @Method(name = "deleteApicert",retries = 0)
    })
public class ApicertFaceImpl implements ApicertFace {

    @Autowired
    IApicertService apicertService;

    @Override
    public Page<ApicertVo> findApicertVoPage(ApicertVo apicertVo, int pageNum, int pageSize) {
        //查询Page<Apicert>图片分页
        Page<Apicert> page = apicertService.findApicertVoPage(apicertVo, pageNum, pageSize);
        //转化Page<Apicert>为Page<ApicertVo>
        Page<ApicertVo> pageVo = new Page<>();
        BeanConv.toBean(page,pageVo);
        //转换List<Apicert>为 List<ApicertVo>
        List<Apicert> apicertList = page.getRecords();
        List<ApicertVo> apicertVoList = BeanConv.toBeanList(apicertList,ApicertVo.class);
        pageVo.setRecords(apicertVoList);
        //返回结果
        return pageVo;
    }

    @Override
    public ApicertVo createApicert(ApicertVo apicertVo) {
        return BeanConv.toBean( apicertService.createApicert(apicertVo), ApicertVo.class);
    }

    @Override
    public Boolean updateApicert(ApicertVo apicertVo) {
        return apicertService.updateApicert(apicertVo);
    }

    @Override
    public Boolean deleteApicert(String[] checkedIds) {
        return apicertService.deleteApicert(checkedIds);
    }

    @Override
    public ApicertVo findApicertByApicertId(Long apicertId) {
        Apicert apicert = apicertService.getById(apicertId);
        return BeanConv.toBean(apicert,ApicertVo.class);
    }

}
